<!DOCTYPE html>
<html lang="en" class="app">
<head>
  <meta charset="utf-8" />
  <title>活动修改</title>
  <meta name="description" description="app, web app, responsive, admin dashboard, admin, flat, flat ui, ui kit, off screen nav" />
  <meta name="viewport" description="width=device-width, initial-scale=1, maximum-scale=1" />
  <link rel="stylesheet" href="${s.base}/js/layui/css/layui.css" media="all" />
  <link rel="stylesheet" href="${s.base}/css/base/base.css" media="all" />
</head>

<body class="childrenBody">
<form class="layui-form" style="width:80%;">
  <input type="hidden" id="id" name="id" value="${activity.id}" />
  <div class="layui-form-item layui-row layui-col-xs12">
    <label class="layui-form-label">活动名称</label>
    <div class="layui-input-block">
      <input type="text" class="layui-input name" id="name" name="name" value="${activity.name}" placeholder="请输入活动名称" lay-verify="required"/>
    </div>
  </div>
  <div class="layui-form-item layui-row layui-col-xs12">
    <label class="layui-form-label">举办方</label>
    <div class="layui-input-block">
      <input type="text" class="layui-input organizers" id="organizers" name="organizers" value="${activity.organizers}" placeholder="请输入举办方" lay-verify="required"/>
    </div>
  </div>
  <div class="layui-form-item layui-row layui-col-xs12">
    <label class="layui-form-label">电话</label>
    <div class="layui-input-block">
      <input type="number" class="layui-input phone" id="phone" name="phone" value="${activity.phone}" placeholder="请输入电话" lay-verify="required"/>
    </div>
  </div>
  <div class="layui-form-item layui-row layui-col-xs12">
    <label class="layui-form-label">地址</label>
    <div class="layui-input-block">
      <input type="text" class="layui-input address" id="address" address="address" value="${activity.address}" placeholder="请输入地址" lay-verify="required"/>
    </div>
  </div>
  <div class="layui-form-item layui-row layui-col-xs12">
    <label class="layui-form-label">费用</label>
    <div class="layui-input-block">
      <input type="number" class="layui-input money" id="money" address="money" value="${activity.money}" placeholder="请输入费用" lay-verify="required"/>
    </div>
  </div>

  <div class="layui-form-item layui-row layui-col-xs12">
    <label class="layui-form-label">图片</label>
    <div class="layui-input-block">
      <div class="famous-upload-pic">
        <img  src="${activity.picture!'/image/icon_addpic.png'}" class="upload-avatar" id="upload-avatar"/>
        <input type="file" name="myfiles" class="upload" id="myFile" onchange="ajaxFileUploads('myFile','picture','upload-avatar')">
        <input type="hidden" class="picture" id="picture"  value="${activity.picture}" />
      </div>
    </div>
  </div>
  <div class="layui-form-item layui-row layui-col-xs12">
    <label class="layui-form-label">开始时间</label>
    <div class="layui-input-block">
      <input type="text" class="layui-input startTime" id="startTime" name="startTime" value="${(activity.startTime?string('yyyy-MM-dd HH:mm:ss'))!''}"
             placeholder="请选择开始时间" maxlength="30" lay-verify="required" autocomplete="off">
    </div>
  </div>

  <div class="layui-form-item layui-row layui-col-xs12">
    <label class="layui-form-label">结束时间</label>
    <div class="layui-input-block">
      <input type="text" class="layui-input keywordThree" id="endTime" name="endTime" value="${(activity.endTime?string('yyyy-MM-dd HH:mm:ss'))!''}"
             placeholder="请选择结束时间" maxlength="30" lay-verify="required" autocomplete="off">
    </div>
  </div>
  <div class="layui-form-item layui-row layui-col-xs12">
    <label class="layui-form-label">描述</label>
    <div class="layui-input-block">
      <div id="descriptionEditor">
        ${activity.description}
      </div>
    </div>
  </div>



  <div class="layui-form-item layui-row layui-col-xs12">
    <div class="layui-input-block">
      <button class="layui-btn layui-btn-sm" lay-submit="" lay-filter="btnSubmit">确定</button>
      <button type="reset" class="layui-btn layui-btn-sm layui-btn-primary closeLay">取消</button>
    </div>
  </div>
</form>
<script type="text/javascript" src="${s.base}/js/layui/layui.js"></script>
<script type="text/javascript" src="${s.base}/js/wangEditor/wangEditor.js"></script>
<script type="text/javascript" src="${s.base}/js/base/jquery-3.2.0.min.js"></script>
<script type="text/javascript" src="${s.base}/js/base/ajaxfileupload.js"></script>
<script>
    var E = window.wangEditor;
    var descriptionEditor = new E('#descriptionEditor');
    descriptionEditor.customConfig.uploadFileName = 'myfiles';
    descriptionEditor.customConfig.uploadImgServer = '/file/fileUploadEditor';
    descriptionEditor.create();
    layui.use(['laydate','form','layer'],function(){
            var form = layui.form
            layer = parent.layer === undefined ? layui.layer : top.layer,
                $ = layui.jquery;
            var laydate = layui.laydate;

            laydate.render({
                elem: '#startTime', //指定元素
                type: 'datetime'
            });
            laydate.render({
                elem: '#endTime', //指定元素
                type: 'datetime'
            });

            form.on("submit(btnSubmit)",function(data){
                //弹出loading
                var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
                var field = data.field;
                var description = descriptionEditor.txt.html();
                // 实际使用时的提交信息
                $.post("/activity/updateOrAddEntity",{
                    id : $("#id").val(),
                    name : $("#name").val(),
                    organizers : $("#organizers").val(),
                    phone : $("#phone").val(),
                    address : $("#address").val(),
                    picture : $("#picture").val(),
                    money : $("#money").val(),
                    startDate : $("#startTime").val(),
                    endDate : $("#endTime").val(),
                    description :description
                },function(result){
                    if(1==result.returnInfo.state){
                        top.layer.close(index);
                        top.layer.msg("操作成功！");
                        layer.closeAll("iframe");
                        //刷新父页面
                        parent.location.reload();
                    }else{
                        top.layer.msg(result.returnInfo.errorMsg);
                    }
                },"json")
                return false;
            });
        })
</script>
</body>
</html>
